<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>无标题文档</title>

<style>
div{width:200px;height:300px;border:1px solid #ddd;}
</style>
<script src="../第十三章事件/eventObject.js" type="text/javascript"></script>
</head>

<body>
	<form id="myForm"  method="post" name="form1" action="http://www.baidu.com" novalidate='true'>
    	<select name="location" id="selLocation1">
        	<option>000</option>
            <option>111</option>
            <option>222</option>
            <option>333</option>
        </select>
        <select name="location" id="selLocation2">
        	<option>aaa</option>
            <option>bbb</option>
        </select>
    </form>
    <script> 
		function serialize(form){
			var parts=[],
			field = null,
			i,
			len,
			j,
			optLen,
			option,
			optValue;
			
			for(i=0, len=form.elements.length; i<len; i++){
				fiele=form.elements[i];
				
				switch(field.type){
					case 'select-one':
					case 'select-multiple':
					
					if(field.name.length){
						
						for(j=0, optLen = field.options.length; j<optLen; j++){
							option=field.options[j];
							
							if(option.selected){
								optValue='';
								if(option.hasAttribute){
									optValue=(option.hasAttribute('value') ? option.value : option.text);	
								}else{
									optValue=(option.attributes['value'].specified ? option.value : option.text);	
								}
								parts.push(encodeURIComponent(field.name) + '=' + encodeURIComponent(optValue));	
							}	
						};	
					}	
						break;
					
					case undefined: //字段集
					
					case 'file': //文件输入
					
					case 'submit'://提交按钮
					
					case 'reset': //重置按钮
					
					case 'button'://自定义按钮
						break;
						
					case 'radio'://单选按钮
					
					case 'checkbox'://复选框
						if(!field.checked){
							break;	
						}
					default:
						//如果字段有name
						if(field.name.length){
							parts.push(encodeURIComponent(field.name) + '=' + encodeURIComponent(field.value));	
						}
				};	
			};	
			
			return parts.join('&');
		};
		serialize();
    </script>
    
</body>
</html>
